package com.yyq.adms.sysmanage.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.yyq.adms.sysmanage.bpo.SysParametersBpo;
import com.yyq.adms.sysmanage.pojo.SysParameters;
import com.yyq.sos.action.BaseAction;
import com.yyq.sos.constants.ActionType;
import com.yyq.sos.util.SysParametersUtil;

@Controller("sysParametersAction")
@Scope("prototype")
public class SysParametersAction extends BaseAction {
	private static final long serialVersionUID = -6920808446100703403L;
	SysParameters po = new SysParameters();
	private SysParametersBpo bpo;

	@Resource(name="sysParametersBpo")
	public void setBpo(SysParametersBpo bpo) {
		bpo.setCls(po.getClass());
		this.bpo = bpo;
	}
	public String execute() throws Exception {
		super.setBpo(bpo);
		super.setObj(po);
		String s = super.execute();
		this.setPo((SysParameters) super.getObj());
		return s;
	}

	public String update() {
		super.update();
		this.setPo((SysParameters) super.getObj());
		SysParametersUtil.getInstance().add(po.getParameter(), po.getValue());
		return ActionType.ACTION_MSG;
	}


	public String add() {
		super.add();
		this.setPo((SysParameters) super.getObj());
		SysParametersUtil.getInstance().add(po.getParameter(), po.getValue());
		return ActionType.ACTION_MSG;
	}


	@Override
	public String delete() {
		String[] ids = (String[])this.getFormValue("ids");
		System.out.println("idslength============="+ids);
		if(ids!=null &&ids.length>0){
			if(bpo.delete((java.io.Serializable[])ids)){
				this.setMsg("{processId:\"1\",msg:\"删除成功\"}");
			}else{
				this.setMsg("{processId:\"-1\",msg:\"删除失败\"}");
			}
		}else{
			this.setMsg("{processId:\"-1\",msg:\"删除失败\"}");
		}
		for(int i=0;i<ids.length;i++){
			SysParametersUtil.getInstance().delete(ids[i]);
		}
		return ActionType.ACTION_MSG;
	}


	public SysParameters getPo() {
		return po;
	}

	public void setPo(SysParameters po) {
		this.po = po;
	}
}
